-- Wiivie.applescript

-- Created by James Madley on 27/12/08.

-- Wiivie. Convert video files to Wii compatible video.
-- Copyright (C) 2008-2009 James David Madley

-- This program is free software; you can redistribute it and/or
-- modify it under the terms of the GNU General Public License
-- as published by the Free Software Foundation; either version 2
-- of the License, or (at your option) any later version.

-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-- GNU General Public License for more details.

-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.


property tabUI_Name : ""
property wiivieFolder_Path : ""
property mencoder : ""
property ffmpeg : ""
property ffmpegUI_RadioOn : false
property input : ""
property output : ""
property dimensions : ""
property dimenWidth : 0
property dimenHeight : 0
property dimenCustom : false
property dimenScaling : false
property fps : ""
property fpsFrame_Rate : 0
property fpsCustom : false
property vbr : ""
property vbrCustom_CheckboxOn : false
property vbrVariable_CheckboxOn : false
property deinterlace : ""
property deinterlaceUI_CheckBoxOn : false
property passUI_CheckBoxOn : false


on clicked theObject -- (*When a UI item is clicked on*)
	if (name of theObject = "windowConvert_Button") then
		windowConvert_Function()
	else if (name of theObject = "mencoderUI_Button") then
		set mencoderMac_Path to choose file with prompt "Select an MEncoder binary file." as text
		set mencoder to POSIX path of mencoderMac_Path -- (*AppleScript uses a different method of representing file paths*)
		set contents of text field "mencoderUI_Textbox" of view "windowEncoder_Inset" of tab view "windowMain_Inset" of window "windowMain" to mencoder
	else if (name of theObject = "ffmpegUI_Button") then
		set ffmpegMac_Path to choose file with prompt "Select an FFmpeg binary file." as text
		set ffmpeg to POSIX path of ffmpegMac_Path -- (*AppleScript uses a different method of representing file paths*)
		set contents of text field "ffmpegUI_Textbox" of view "windowEncoder_Inset" of tab view "windowMain_Inset" of window "windowMain" to ffmpeg
	else if (name of theObject = "inputUI_Button") then
		set inputMac_Path to choose file with prompt "Select the movie file to be converted." as text
		set input to POSIX path of inputMac_Path -- (*AppleScript uses a different method of representing file paths*)
		set contents of text field "inputUI_Textbox" of window "windowMain" to input
	else if (name of theObject = "outputUI_Button") then
		set outputMac_Path to choose file name with prompt "Select a destination for your converted file." as text
		set output to POSIX path of outputMac_Path -- (*AppleScript uses a different method of representing file paths*)
		set contents of text field "outputUI_Textbox" of window "windowMain" to output & ".avi"
	else if (name of theObject = "encoderUI_Radio") then
		if (current row of matrix "encoderUI_Radio" of view "windowEncoder_Inset" of tab view "windowMain_Inset" of window "windowMain" = 1) then -- (*MEncoder*)
			set contents of text field "ffmpegUI_Textbox" of view "windowEncoder_Inset" of tab view "windowMain_Inset" of window "windowMain" to ""
			set enabled of button "ffmpegUI_Button" of view "windowEncoder_Inset" of tab view "windowMain_Inset" of window "windowMain" to false
			set enabled of text field "ffmpegUI_Textbox" of view "windowEncoder_Inset" of tab view "windowMain_Inset" of window "windowMain" to false
			set enabled of button "mencoderUI_Button" of view "windowEncoder_Inset" of tab view "windowMain_Inset" of window "windowMain" to true
			set enabled of text field "mencoderUI_Textbox" of view "windowEncoder_Inset" of tab view "windowMain_Inset" of window "windowMain" to true
			set ffmpeg to ""
			set ffmpegUI_RadioOn to false
		else if (current row of matrix "encoderUI_Radio" of view "windowEncoder_Inset" of tab view "windowMain_Inset" of window "windowMain" = 2) then -- (*FFmpeg*)
			set contents of text field "mencoderUI_Textbox" of view "windowEncoder_Inset" of tab view "windowMain_Inset" of window "windowMain" to ""
			set enabled of button "mencoderUI_Button" of view "windowEncoder_Inset" of tab view "windowMain_Inset" of window "windowMain" to false
			set enabled of text field "mencoderUI_Textbox" of view "windowEncoder_Inset" of tab view "windowMain_Inset" of window "windowMain" to false
			set enabled of button "ffmpegUI_Button" of view "windowEncoder_Inset" of tab view "windowMain_Inset" of window "windowMain" to true
			set enabled of text field "ffmpegUI_Textbox" of view "windowEncoder_Inset" of tab view "windowMain_Inset" of window "windowMain" to true
			set mencoder to ""
			set ffmpegUI_RadioOn to true
		end if
	else if (name of theObject = "dimenCustom_Checkbox") then
		if (ffmpegUI_RadioOn is false) then
			if (dimenCustom is true) then
				set enabled of popup button "dimenScaling_PopupMenu" of view "dimenUI_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" to true
				set enabled of button "dimenScaling_Checkbox" of view "dimenScaling_Inset" of view "dimenUI_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" to true
				set enabled of text field "dimenCustomWidth_Textbox" of view "dimenCustom_Inset" of view "dimenUI_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" to false
				set enabled of text field "dimenCustomHeight_Textbox" of view "dimenCustom_Inset" of view "dimenUI_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" to false
				set enabled of text field "dimenScalingWidth_Textbox" of view "dimenScaling_Inset" of view "dimenUI_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" to false
				set enabled of text field "dimenScalingHeight_Textbox" of view "dimenScaling_Inset" of view "dimenUI_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" to false
				set contents of text field "dimenCustomWidth_Textbox" of view "dimenCustom_Inset" of view "dimenUI_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" to ""
				set contents of text field "dimenCustomHeight_Textbox" of view "dimenCustom_Inset" of view "dimenUI_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" to ""
				set contents of text field "dimenScalingWidth_Textbox" of view "dimenScaling_Inset" of view "dimenUI_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" to ""
				set contents of text field "dimenScalingHeight_Textbox" of view "dimenScaling_Inset" of view "dimenUI_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" to ""
				set dimenCustom to false
			else if (dimenCustom is false) then
				set enabled of popup button "dimenScaling_PopupMenu" of view "dimenUI_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" to false
				set enabled of button "dimenScaling_Checkbox" of view "dimenScaling_Inset" of view "dimenUI_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" to false
				set enabled of text field "dimenCustomWidth_Textbox" of view "dimenCustom_Inset" of view "dimenUI_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" to true
				set enabled of text field "dimenCustomHeight_Textbox" of view "dimenCustom_Inset" of view "dimenUI_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" to true
				set dimenCustom to true
			end if
		else if (ffmpegUI_RadioOn is true) then
			if (dimenCustom is true) then
				set enabled of text field "dimenCustomWidth_Textbox" of view "dimenCustom_Inset" of view "dimenUI_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" to false
				set enabled of text field "dimenCustomHeight_Textbox" of view "dimenCustom_Inset" of view "dimenUI_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" to false
				set contents of text field "dimenCustomWidth_Textbox" of view "dimenCustom_Inset" of view "dimenUI_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" to ""
				set contents of text field "dimenCustomHeight_Textbox" of view "dimenCustom_Inset" of view "dimenUI_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" to ""
				set dimenCustom to false
			else if (dimenCustom is false) then
				set enabled of text field "dimenCustomWidth_Textbox" of view "dimenCustom_Inset" of view "dimenUI_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" to true
				set enabled of text field "dimenCustomHeight_Textbox" of view "dimenCustom_Inset" of view "dimenUI_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" to true
				set dimenCustom to true
			end if
		end if
	else if (name of theObject = "dimenScaling_Checkbox") then
		if (dimenScaling is true) then -- (*If dimenScaling_Checkbox is on when pushed*)
			set enabled of popup button "dimenScaling_PopupMenu" of view "dimenUI_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" to true
			set enabled of button "dimenCustom_Checkbox" of view "dimenCustom_Inset" of view "dimenUI_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" to true
			set enabled of text field "dimenCustomWidth_Textbox" of view "dimenCustom_Inset" of view "dimenUI_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" to false
			set enabled of text field "dimenCustomHeight_Textbox" of view "dimenCustom_Inset" of view "dimenUI_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" to false
			set enabled of text field "dimenScalingWidth_Textbox" of view "dimenScaling_Inset" of view "dimenUI_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" to false
			set contents of text field "dimenCustomWidth_Textbox" of view "dimenCustom_Inset" of view "dimenUI_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" to ""
			set contents of text field "dimenCustomHeight_Textbox" of view "dimenCustom_Inset" of view "dimenUI_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" to ""
			set contents of text field "dimenScalingWidth_Textbox" of view "dimenScaling_Inset" of view "dimenUI_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" to ""
			set dimenScaling to false
		else if (dimenScaling is false) then -- (*If dimenScaling_Checkbox is off when pushed*)
			set enabled of popup button "dimenScaling_PopupMenu" of view "dimenUI_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" to false
			set enabled of button "dimenCustom_Checkbox" of view "dimenCustom_Inset" of view "dimenUI_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" to false
			set enabled of text field "dimenScalingWidth_Textbox" of view "dimenScaling_Inset" of view "dimenUI_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" to true
			set dimenScaling to true
		end if
	else if (name of theObject = "fpsCustom_Checkbox") then
		if (fpsCustom is true) then -- (*If fpsCustom_Checkbox is on when pushed*)
			set enabled of popup button "fpsStandards_PopupMenu" of view "fpsUI_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" to true
			set enabled of text field "fpsCustom_Textbox" of view "fpsCustom_Inset" of view "fpsUI_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" to false
			set contents of text field "fpsCustom_Textbox" of view "fpsCustom_Inset" of view "fpsUI_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" to ""
			set fpsCustom to false
		else if (fpsCustom is false) then -- (*If fpsCustom_Checkbox is off when pushed*)
			set enabled of popup button "fpsStandards_PopupMenu" of view "fpsUI_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" to false
			set enabled of text field "fpsCustom_Textbox" of view "fpsCustom_Inset" of view "fpsUI_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" to true
			set fpsCustom to true
		end if
	else if (name of theObject = "vbrCustom_Checkbox") then
		if (vbrCustom_CheckboxOn is false) then
			set enabled of text field "vbrCustom_Textbox" of view "vbrCustom_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" to true
			set enabled of button "vbrVariable_Checkbox" of view "vbrCustom_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" to false
			set vbrCustom_CheckboxOn to true
		else if (vbrCustom_CheckboxOn is true) then
			set enabled of text field "vbrCustom_Textbox" of view "vbrCustom_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" to false
			set contents of text field "vbrCustom_Textbox" of view "vbrCustom_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" to ""
			set enabled of button "vbrVariable_Checkbox" of view "vbrCustom_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" to true
			set vbr to ""
			set vbrCustom_CheckboxOn to false
		end if
	else if (name of theObject = "vbrVariable_Checkbox") then
		if (vbrVariable_CheckboxOn is false) then
			set enabled of popup button "vbrVariable_PopupMenu" of view "vbrCustom_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" to true
			set enabled of button "vbrCustom_Checkbox" of view "vbrCustom_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" to false
			set vbrVariable_CheckboxOn to true
		else if (vbrVariable_CheckboxOn is true) then
			set enabled of popup button "vbrVariable_PopupMenu" of view "vbrCustom_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" to false
			set title of popup button "vbrVariable_PopupMenu" of view "vbrCustom_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" to ""
			set enabled of button "vbrCustom_Checkbox" of view "vbrCustom_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" to true
			set vbrVariable_CheckboxOn to false
		end if
	else if (name of theObject = "deinterlaceUI_Checkbox") then
		if (deinterlaceUI_CheckBoxOn is true) then -- (*If deinterlaceUI_Checkbox is on when pushed*)
			set deinterlace to ""
			set deinterlaceUI_CheckBoxOn to false
		else if (deinterlaceUI_CheckBoxOn is false) then -- (*If deinterlaceUI_Checkbox is off when pushed*)
			deinterlaceUI_SetFunction()
			set deinterlaceUI_CheckBoxOn to true
		end if
	else if (name of theObject = "passUI_Checkbox") then
		passUI_SetFunction()
	end if
end clicked


on selected tab view item theObject tab view item tabViewItem -- (*When a tab is selected*)
	set tabUI_Name to name of tabViewItem -- (*Makes this easier*)
	if (name of theObject = "windowMain_Inset") then
		if (tabUI_Name = "windowEncoder_tabViewItem") then
			-- (*Do nothing*)
		else if (tabUI_Name = "windowVideo_tabViewItem") then
			if (ffmpegUI_RadioOn is false) then -- (*FFmpeg not selected*)
				if (dimenCustom is false and dimenScaling is false) then -- (*Custom dimensions and custom scaling both turned off*)
					set enabled of popup button "dimenScaling_PopupMenu" of view "dimenUI_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" to true
					set enabled of button "dimenCustom_Checkbox" of view "dimenCustom_Inset" of view "dimenUI_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" to true
					set enabled of button "dimenScaling_Checkbox" of view "dimenScaling_Inset" of view "dimenUI_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" to true
				else if (dimenCustom is true) then -- (*Only custom dimensions turned on*)
					set enabled of button "dimenCustom_Checkbox" of view "dimenCustom_Inset" of view "dimenUI_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" to true
				else if (dimenScaling is true) then -- (*Only custom scaling turned on*)
					set enabled of button "dimenScaling_Checkbox" of view "dimenScaling_Inset" of view "dimenUI_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" to true
				end if
				set enabled of button "vbrCustom_Checkbox" of view "vbrCustom_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" to false
				set enabled of button "vbrVariable_Checkbox" of view "vbrCustom_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" to false
				set enabled of text field "vbrCustom_Textbox" of view "vbrCustom_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" to false
				set enabled of popup button "vbrVariable_PopupMenu" of view "vbrCustom_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" to false
				set state of button "vbrCustom_Checkbox" of view "vbrCustom_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" to 0
				set state of button "vbrVariable_Checkbox" of view "vbrCustom_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" to 0
				set contents of text field "vbrCustom_Textbox" of view "vbrCustom_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" to ""
				set title of popup button "vbrVariable_PopupMenu" of view "vbrCustom_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" to ""
				set vbrCustom_CheckboxOn to false
				set vbrVariable_CheckboxOn to false
			else if (ffmpegUI_RadioOn is true) then -- (*FFmpeg selected*)
				set enabled of popup button "dimenScaling_PopupMenu" of view "dimenUI_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" to false
				set enabled of button "dimenCustom_Checkbox" of view "dimenCustom_Inset" of view "dimenUI_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" to true
				set enabled of button "dimenScaling_Checkbox" of view "dimenScaling_Inset" of view "dimenUI_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" to false
				set enabled of text field "dimenScalingWidth_Textbox" of view "dimenScaling_Inset" of view "dimenUI_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" to false
				set state of button "dimenScaling_Checkbox" of view "dimenScaling_Inset" of view "dimenUI_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" to 0
				set enabled of button "vbrCustom_Checkbox" of view "vbrCustom_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" to true
				set enabled of button "vbrVariable_Checkbox" of view "vbrCustom_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" to true
				set dimenScaling to false
			end if
		else if (tabUI_Name = "windowOptions_tabViewItem") then
			if (ffmpegUI_RadioOn is false) then -- (*FFmpeg not selected*)
				set enabled of button "passUI_Checkbox" of view "optionsVideo_Inset" of view "windowOptions_Inset" of tab view "windowMain_Inset" of window "windowMain" to false
				set state of button "passUI_Checkbox" of view "optionsVideo_Inset" of view "windowOptions_Inset" of tab view "windowMain_Inset" of window "windowMain" to 0
			else if (ffmpegUI_RadioOn is true) then -- (*FFmpeg selected*)
				set enabled of button "passUI_Checkbox" of view "optionsVideo_Inset" of view "windowOptions_Inset" of tab view "windowMain_Inset" of window "windowMain" to true
			end if
		end if
	end if
end selected tab view item


on choose menu item theObject -- (*When a menu item is chosen from a popup menu*)
	dimenScaling_SetFunction()
	fpsStandards_SetFunction()
	vbrVariable_SetFunction()
end choose menu item


on changed theObject -- (*If any of the text boxes are changed, set custom dimensions and frame rate variables.*)
	dimenCustom_SetFunction()
	fpsCustom_SetFunction()
	vbrCustom_SetFunction()
end changed


on wiivieFolder_PathSetFunction()
	set wiivieFolderMac_Path to (path to me) as text
	set wiivieFolder_Path to POSIX path of wiivieFolderMac_Path
	set wiivieFolder_Path to do shell script "dirname '" & wiivieFolder_Path & "'"
end wiivieFolder_PathSetFunction


on windowConvert_Function()
	wiivieFolder_PathSetFunction()
	set wiivieBundle_Path to call method "bundlePath" of object main bundle -- (*Work out where Wiivie.app is located.*)
	start progress indicator "windowConvert_ProgressBar" of window "windowMain" -- (*Start the progress bar*)
	if (ffmpegUI_RadioOn is false) then -- (*MEncoder*)
		do shell script " '" & mencoder & "' '" & input & "' -ovc lavc -lavcopts vcodec=mjpeg -oac pcm " & dimensions & " " & deinterlace & " " & fps & " -o '" & output & ".avi' &> /dev/null &"
		do shell script "osascript '" & wiivieBundle_Path & "/Contents/Resources/mencoderConvert_ProgressBarStop' &> /dev/null &" -- (*So the progress bar eventually stops*)
	else if (ffmpegUI_RadioOn is true) then -- (*FFmpeg*)
		if (passUI_CheckBoxOn is false) then
			do shell script " '" & ffmpeg & "' -i '" & input & "' -y -vcodec mjpeg " & dimensions & " " & deinterlace & " -acodec pcm_u8 " & fps & " " & vbr & " '" & output & ".avi' &> /dev/null &"
			do shell script "osascript '" & wiivieBundle_Path & "/Contents/Resources/ffmpegConvert_ProgressBarStop' &> /dev/null &" -- (*So the progress bar eventually stops*)
		else if (passUI_CheckBoxOn is true) then
			do shell script " '" & ffmpeg & "' -i '" & input & "' -y -vcodec mjpeg " & dimensions & " " & deinterlace & " -acodec pcm_u8 " & fps & " " & vbr & " -pass 1 '" & output & ".avi'"
			do shell script " '" & ffmpeg & "' -i '" & input & "' -y -vcodec mjpeg " & dimensions & " " & deinterlace & " -acodec pcm_u8 " & fps & " " & vbr & " -pass 2 -passlogfile '" & wiivieFolder_Path & "/ffmpeg2pass' '" & output & ".avi' &> /dev/null &"
			do shell script "osascript '" & wiivieBundle_Path & "/Contents/Resources/ffmpegConvert_ProgressBarStop' &> /dev/null &" -- (*So the progress bar eventually stops*)
		end if
	end if
end windowConvert_Function


on dimenScaling_SetFunction()
	if (ffmpegUI_RadioOn is false and dimenCustom is false) then
		if (title of current menu item of popup button "dimenScaling_PopupMenu" of view "dimenUI_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" = "Default") then
			set dimensions to ""
		else if (title of current menu item of popup button "dimenScaling_PopupMenu" of view "dimenUI_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" = "Tiny") then
			set dimensions to "-vf scale -zoom -xy 160"
		else if (title of current menu item of popup button "dimenScaling_PopupMenu" of view "dimenUI_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" = "Small") then
			set dimensions to "-vf scale -zoom -xy 320"
		else if (title of current menu item of popup button "dimenScaling_PopupMenu" of view "dimenUI_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" = "Normal") then
			set dimensions to "-vf scale -zoom -xy 640"
		else if (title of current menu item of popup button "dimenScaling_PopupMenu" of view "dimenUI_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" = "Large") then
			set dimensions to "-vf scale -zoom -xy 720"
		else if (title of current menu item of popup button "dimenScaling_PopupMenu" of view "dimenUI_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" = "Huge") then
			set dimensions to "-vf scale -zoom -xy 848"
		end if
	end if
end dimenScaling_SetFunction


on dimenCustom_SetFunction()
	if (ffmpegUI_RadioOn is false) then -- (*MEncoder*)
		if (dimenCustom is true) then
			set dimenWidth to contents of text field "dimenCustomWidth_Textbox" of view "dimenCustom_Inset" of view "dimenUI_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain"
			set dimenHeight to contents of text field "dimenCustomHeight_Textbox" of view "dimenCustom_Inset" of view "dimenUI_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain"
			set dimensions to "-vf scale=" & dimenWidth & ":" & dimenHeight
		else if (dimenScaling is true) then
			set dimenScalingWidth to contents of text field "dimenScalingWidth_Textbox" of view "dimenScaling_Inset" of view "dimenUI_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain"
			set dimensions to "-vf scale -zoom -xy " & dimenScalingWidth
		end if
	else if (dimenCustom is true and ffmpegUI_RadioOn is true) then -- (*FFmpeg*)
		set dimenWidth to contents of text field "dimenCustomWidth_Textbox" of view "dimenCustom_Inset" of view "dimenUI_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain"
		set dimenHeight to contents of text field "dimenCustomHeight_Textbox" of view "dimenCustom_Inset" of view "dimenUI_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain"
		set dimensions to "-s " & dimenWidth & "x" & dimenHeight
	end if
end dimenCustom_SetFunction


on fpsStandards_SetFunction()
	if (ffmpegUI_RadioOn is false and fpsCustom is false) then -- (*FFmpeg not selected*)
		if (title of current menu item of popup button "fpsStandards_PopupMenu" of view "fpsUI_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" = "Default") then
			set fps to ""
		else if (title of current menu item of popup button "fpsStandards_PopupMenu" of view "fpsUI_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" = "PAL") then
			set fps to "-ofps 25"
		else if (title of current menu item of popup button "fpsStandards_PopupMenu" of view "fpsUI_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" = "NTSC") then
			set fps to "-ofps 29.97"
		else if (title of current menu item of popup button "fpsStandards_PopupMenu" of view "fpsUI_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" = "NTSC Film") then
			set fps to "-ofps 23.976"
		end if
	else if (ffmpegUI_RadioOn is true and fpsCustom is false) then -- (*FFmpeg selected*)
		if (title of current menu item of popup button "fpsStandards_PopupMenu" of view "fpsUI_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" = "Default") then
			set fps to ""
		else if (title of current menu item of popup button "fpsStandards_PopupMenu" of view "fpsUI_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" = "PAL") then
			set fps to "-r 25"
		else if (title of current menu item of popup button "fpsStandards_PopupMenu" of view "fpsUI_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" = "NTSC") then
			set fps to "-r 29.97"
		else if (title of current menu item of popup button "fpsStandards_PopupMenu" of view "fpsUI_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain" = "NTSC Film") then
			set fps to "-r 23.976"
		end if
	end if
end fpsStandards_SetFunction


on fpsCustom_SetFunction()
	if (fpsCustom is true and ffmpegUI_RadioOn is false) then -- (*MEncoder*)
		set fpsFrame_Rate to contents of text field "fpsCustom_Textbox" of view "fpsCustom_Inset" of view "fpsUI_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain"
		set fps to "-ofps " & fpsFrame_Rate
	else if (fpsCustom is true and ffmpegUI_RadioOn is true) then -- (*FFmpeg*)
		set fpsFrame_Rate to contents of text field "fpsCustom_Textbox" of view "fpsCustom_Inset" of view "fpsUI_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain"
		set fps to "-r " & fpsFrame_Rate
	end if
end fpsCustom_SetFunction


on vbrCustom_SetFunction()
	if (vbrCustom_CheckboxOn is true) then
		set vbr to contents of text field "vbrCustom_Textbox" of view "vbrCustom_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain"
		set vbr to "-b " & vbr
	end if
end vbrCustom_SetFunction


on vbrVariable_SetFunction()
	if (vbrVariable_CheckboxOn is true) then
		set vbr to title of current menu item of popup button "vbrVariable_PopupMenu" of view "vbrCustom_Inset" of view "windowVideo_Inset" of tab view "windowMain_Inset" of window "windowMain"
		set vbr to "-qscale " & vbr
	end if
end vbrVariable_SetFunction


on deinterlaceUI_SetFunction()
	if (ffmpegUI_RadioOn is false) then
		set deinterlace to "-vf pp=lb"
	else if (ffmpegUI_RadioOn is true) then
		set deinterlace to "-deinterlace"
	end if
end deinterlaceUI_SetFunction


on passUI_SetFunction()
	if (passUI_CheckBoxOn is false) then
		set passUI_CheckBoxOn to true
	else if (passUI_CheckBoxOn is true) then
		set passUI_CheckBoxOn to false
	end if
end passUI_SetFunction
